let movie_yh_controller = {
    // 查询所有的电影信息初始化热播电影
    findMovieAll: function (pageNum, pageSize) {
        axios({
            url: "/admin/movie/all",
            method: "GET",
            params: {
                pageNum: pageNum,
                pageSize: pageSize,
            }
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.movies = value.data.data.list;
                vueapp.page = value.data.data;
            } else {
                vueapp.$alert(value.data.msg, '提示', {
                    confirmButtonText: '确定',
                });
            }
        })
    },

    // 根据ID查询影片信息
    findMovieById: function (movieId) {
        axios({
            url: "/admin/movie/movie",
            method: "GET",
            params: {
                movieId: movieId,
            }
        }).then(function (value) {
            if (value.data.code == 200) {
                var movie = value.data.data;
                var movieDuration = movie.movieDuration;
                // 处理影片的显示时长(去除字符串中的'分钟'字样)
                if (movieDuration != null) {
                    movie.movieDuration = movieDuration.slice(0, (movieDuration.length - 2));
                }
                var movieType = movie.movieType;
                // 初始化已经选中的影片类型
                if (movieType != null) {
                    vueapp.updateMovie.excludeType = movieType.split(" ");
                }
                vueapp.updateMovie.movie = movie;
            } else {
                vueapp.$alert(value.data.msg, '提示', {
                    confirmButtonText: '确定',
                });
            }
        })
    },

    // 查询所有的导演信息
    findDirectorAll: function () {
        axios({
            url: "/admin/director/all",
            method: "GET"
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.directorList = value.data.data;
            } else {
                vueapp.$alert(value.data.msg, '提示', {
                    confirmButtonText: '确定',
                });
            }
        })
    },

    // 查询所有的演员信息
    findActorAll: function () {
        axios({
            url: "/admin/actor/all",
            method: "GET"
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.actorList = value.data.data;
            } else {
                vueapp.$alert(value.data.msg, '提示', {
                    confirmButtonText: '确定',
                });
            }
        })
    },

    // 查询所有的影片类型
    findMovieTypeAll: function () {
        axios({
            url: "/admin/movie/type/all",
            method: "GET"
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.typeList = value.data.data;
            } else {
                vueapp.$alert(value.data.msg, '提示', {
                    confirmButtonText: '确定',
                });
            }
        })
    },

    // 查询所有的制片地区
    findMovieCountryAll: function () {
        axios({
            url: "/admin/movie/country/all",
            method: "GET"
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.countryList = value.data.data;
            } else {
                vueapp.$alert(value.data.msg, '提示', {
                    confirmButtonText: '确定',
                });
            }
        })
    },

    // 添加影片
    addMovie: function () {
        // 刷新出演人
        this.initActorData(false)
        // 以表单数据传输
        var fromData = new FormData();
        var movieCnName = this.movie.movieCnName;
        if (movieCnName == null || movieCnName == "") {
            this.$message({
                message: '影片的名字不能为空哦！',
                type: 'warning'
            });
            return;
        }
        var movieActor = this.movie.movieActor;
        if (movieActor == null || movieActor.length ==0) {
            this.$message({
                message: '饰演列表不能为空哦！',
                type: 'warning'
            });
            return;
        }
        var movieDirectorId = this.movie.movieDirectorId;
        if (movieDirectorId == null || movieDirectorId == "") {
            this.$message({
                message: '导演信息未选中',
                type: 'warning'
            });
            return;
        }
        // 获取图片
        var file = document.getElementById("addFile").files[0];
        // 如果未选中图片就不封装该属性
        if (file != undefined) {
            fromData.set("movieFile", file)
        }
        fromData.set("movieCnName", movieCnName)
        fromData.set("movieActor", movieActor)
        fromData.set("movieDirectorId", movieDirectorId)
        var movieFgName = this.movie.movieFgName;
        if (movieFgName != null) {
            fromData.set("movieFgName", movieFgName)
        }
        fromData.set("movieStar", this.movie.movieStar)
        fromData.set("movieActorIds", this.movie.movieActorIds)
        var movieExplain = this.movie.movieExplain;
        if (movieExplain != null) {
            fromData.set("movieExplain", movieExplain)
        }
        var movieDuration = this.movie.movieDuration;
        if (movieDuration == null || movieDuration == "") {
            movieDuration = 0;
        }
        fromData.set("movieDuration", movieDuration + '分钟')
        var movieReleaseDate = this.movie.movieReleaseDate;
        if (movieReleaseDate != null && movieReleaseDate != "") {
            fromData.set("movieReleaseDate", movieReleaseDate)
        }
        var movieCountry = this.movie.movieCountry;
        if (movieCountry != null && movieCountry != "") {
            fromData.set("movieCountry", movieCountry)
        }
        var movieType = this.movie.movieType;
        if (movieType!= null && movieType != "") {
            fromData.set("movieType", movieType)
        }
        axios({
            url: "/admin/movie/add",
            method: "POST",
            data: fromData
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.$message({
                    message: '添加成功！请重新刷新网页',
                    type: 'success'
                });
            } else {
                vueapp.$message.error('出现了意外错误！');
            }
        })
    },

    // 修改影片
    updateToMovie: function () {
        // 以表单数据传输
        var fromData = new FormData();
        var movieCnName = this.updateMovie.movie.movieCnName;
        if (movieCnName == null || movieCnName == "") {
            this.$message({
                message: '影片的名字不能为空哦！',
                type: 'warning'
            });
            return;
        }
        fromData.set("movieCnName", movieCnName)
        var movieActor = this.updateMovie.movie.movieActor;
        if (movieActor == null || movieActor.length ==0) {
            this.$message({
                message: '饰演列表不能为空哦！',
                type: 'warning'
            });
            return;
        }
        fromData.set("movieActor", movieActor)
        var movieDirectorId = this.updateMovie.movie.movieDirectorId;
        if (movieDirectorId == null || movieDirectorId == "") {
            this.$message({
                message: '导演信息未选中',
                type: 'warning'
            });
            return;
        }
        fromData.set("movieDirectorId", movieDirectorId)
        var movieReleaseDate = this.updateMovie.movie.movieReleaseDate;
        if (movieReleaseDate == "") {
            this.$message({
                message: '影片的上映时间不能修改为空！',
                type: 'warning'
            });
            return;
        }
        if (movieReleaseDate != null) {
            fromData.set("movieReleaseDate", movieReleaseDate)
        }
        // 获取图片
        var file = document.getElementById("updateFile").files[0];
        // 如果未选中图片就不封装该属性
        if (file != undefined) {
            fromData.set("movieFile", file)
        }
        fromData.set("movieId", this.updateMovie.movie.movieId)
        var movieFgName = this.updateMovie.movie.movieFgName;
        if (movieFgName != null) {
            fromData.set("movieFgName", movieFgName)
        }
        var movieStar = this.updateMovie.movie.movieStar;
        if (movieStar != null) {
            fromData.set("movieStar", movieStar)
        }
        fromData.set("movieActorIds", this.updateMovie.movie.movieActorIds)
        var movieExplain = this.updateMovie.movie.movieExplain;
        if (movieExplain != null) {
            fromData.set("movieExplain", movieExplain)
        }
        var movieDuration = this.updateMovie.movie.movieDuration;
        if (movieDuration == null && movieDuration == "") {
            movieDuration = 0;
        }
        fromData.set("movieDuration", movieDuration + '分钟')
        var movieCountry = this.updateMovie.movie.movieCountry;
        if (movieCountry != null) {
            fromData.set("movieCountry", movieCountry)
        }
        var movieType = this.updateMovie.movie.movieType;
        if (movieType != null) {
            fromData.set("movieType", movieType)
        }
        var movieScore = this.updateMovie.movie.movieScore;
        if (movieScore == null && movieScore == "") {
            movieScore = 0;
        }
        fromData.set("movieScore", movieScore)
        var movieState = this.updateMovie.movie.movieState;
        if (movieState == null && movieState == "") {
            movieState = 0;
        }
        fromData.set("movieState", movieState)
        axios({
            url: "/admin/movie/update",
            method: "POST",
            data: fromData
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.$message({
                    message: '修改成功！请重新刷新网页',
                    type: 'success'
                });
            } else {
                vueapp.$message.error('出现了意外错误！');
            }
        })
    },

    // 删除影片
    deleteMovie: function (movieId) {
        axios({
            url: "/admin/movie/del",
            method: "GET",
            params: {
                movieId: movieId,
            }
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.$alert('删除成功！', '提示', {
                    confirmButtonText: '确定',
                    callback: function action() {
                        location.reload();
                    }
                })
            } else {
                vueapp.$message.error('出现了意外错误！');
            }
        })
    },

    // 添加演员
    addActor: function () {
        // 获取图片
        var file = document.getElementById("addActorImg").files[0];
        // 以表单数据传输
        var fromData = new FormData();
        // 如果未选中图片就不封装该属性
        if (file != undefined) {
            fromData.set("actorFile", file)
        }
        fromData.set("actorName", this.actor.actorName)
        axios({
            url: "/admin/actor/add",
            method: "POST",
            data: fromData
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.$message({
                    message: '添加成功！',
                    type: 'success'
                });
            } else {
                vueapp.$message.error('出现了意外错误！');
            }
        })
    },

    // 添加导演
    addDirector: function () {
        // 获取图片
        var file = document.getElementById("addDireImg").files[0];
        // 以表单数据传输
        var fromData = new FormData();
        // 如果未选中图片就不封装该属性
        if (file != undefined) {
            fromData.set("directorFile", file)
        }
        fromData.set("directorName", this.director.directorName)
        axios({
            url: "/admin/director/add",
            method: "POST",
            data: fromData
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.$message({
                    message: '添加成功！',
                    type: 'success'
                });
            } else {
                vueapp.$message.error('出现了意外错误！');
            }
        })
    },

    // 添加制片区域
    addMovieCountry: function () {
        axios({
            url: "/admin/movie/add/country",
            method: "POST",
            data: {
                countryName: this.country.countryName,
            }
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.$message({
                    message: '添加成功！',
                    type: 'success'
                });
                vueapp.country.countryName = '';
            } else {
                vueapp.$message.error('出现了意外错误！');
            }
        })
    },

    // 添加影片类型
    addMovieType: function () {
        axios({
            url: "/admin/movie/add/type",
            method: "POST",
            data: {
                typeName: this.movieType.typeName,
            }
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.$message({
                    message: '添加成功！',
                    type: 'success'
                });
                vueapp.movieType.typeName = '';
            } else {
                vueapp.$message.error('出现了意外错误！');
            }
        })
    },

    // 影片预热
    moviePreheat: function () {
        axios({
            url: "/admin/movie/preheat",
            method: "GET",
        }).then(function (value) {
            if (value.data.code == 200) {
                vueapp.$message({
                    message: '预热请求已送达！',
                    type: 'success'
                });
            } else {
                vueapp.$message.error('出现了意外的错误导致无法预热！');
            }
        })
    },
}